
component  extends="ModelGlue.gesture.controller.Controller" output="false" beans="core"
{
	public ModelGlue.gesture.controller.Controller function init( required Any modelGlue){
		
		super.init( arguments.modelGlue );
		
		return this;
	}
	
	public ModelGlue.Core.Event function login( required Any event ){
		
		var service = beans.core.getService( 'Security' );
		var result = "";
		
		if( not len( arguments.event.getValue('username') ) or not len( arguments.event.getValue('password') ) ){
		
			arguments.event.addResult( "invalid" );	
		
		}
		
		result = service.login( arguments.event.getValue('username' ), 
								 arguments.event.getValue('password' ) );
								 
		 if( result ){
		 
		 	arguments.event.addResult( "success" );
			
		}else{

			arguments.event.addResult( "invalid" );		 
		 
		 }
		
		return arguments.event;
	}
	
	public ModelGlue.Core.Event function logout( required Any event ){
		
		var service = beans.core.getService( 'Security' );
		
		service.logout();
		
		return arguments.event;
	}
	
	public ModelGlue.Core.Event function getLogin( required Any event ){
		
		var service = beans.core.getService( 'Security' );
		var result = "";
		
		result = service.getLogin();
		
		arguments.event.setValue( 'login', result );
		
		if( result.getStatus() ){
		
			arguments.event.addResult( 'isLogged' );
		
		}else{
		
			arguments.event.addResult( 'isNotLogged' );
		
		}
		
		return arguments.event;
	}
	
	
	
}
